<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/3/14
 * Time: 13:08
 */

namespace app\index\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Validate;
use app\index\validate\Valid;

class Xtbf extends Common
{
    /**
     * 所有协同拜访
     */
    public function allsynergybf(){
        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $xtrxm = $this->request->param('xtrxm');
        $xtrgw = $this->request->param('xtrgw');
        $bflx = $this->request->param('bflx');
        $fq = $this->request->param('fq');
        $sf = $this->request->param('sf');
        $cs = $this->request->param('cs');
        $jxsmc = $this->request->param('jxsmc');
        $wdmc = $this->request->param('wdmc');
        $this->assign([
            'xtrxm'=>$xtrxm,
            'xtrgw'=>$xtrgw,
            'bflx'=>$bflx,
            'fq'=>$fq,
            'sf'=>$sf,
            'cs'=>$cs,
            'jxsmc'=>$jxsmc,
            'wdmc'=>$wdmc,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        if($xtrxm){
            $where['xtpfrxm'] = ['like',"%{$xtrxm}%"];
        }
        if($xtrgw){
            $where['gw'] = ['like',"%{$xtrgw}%"];
        }
        if($bflx){
            $where['bflx'] = ['like',"%{$bflx}%"];
        }
        if($fq){
            $where['fq'] = ['like',"%{$fq}%"];
        }
        if($sf){
            $where['sf'] = ['like',"%{$sf}%"];
        }
        if($cs){
            $where['cs'] = ['like',"%{$cs}%"];
        }
        if($cs){
            $where['jxsmc'] = ['like',"%{$jxsmc}%"];
        }
        if($wdmc){
            $where['wdmc'] = ['like',"%{$wdmc}%"];
        }
        if($start&&$end){
            $where['bfrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['bfrq'] = ['>',$start];
        }elseif($end){
            $where['bfrq'] = ['<',$end];
        }

        $count = db('yd_xtbf')->where($where)->count();
        $data = db('yd_xtbf')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 所属协同拜访
     */
    public function tosynergybf(){

        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $xtrxm = $this->request->param('xtrxm');
        $xtrgw = $this->request->param('xtrgw');
        $bflx = $this->request->param('bflx');
        $fq = $this->request->param('fq');
        $sf = $this->request->param('sf');
        $cs = $this->request->param('cs');
        $jxsmc = $this->request->param('jxsmc');
        $wdmc = $this->request->param('wdmc');
        $this->assign([
            'xtrxm'=>$xtrxm,
            'xtrgw'=>$xtrgw,
            'bflx'=>$bflx,
            'fq'=>$fq,
            'sf'=>$sf,
            'cs'=>$cs,
            'jxsmc'=>$jxsmc,
            'wdmc'=>$wdmc,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['bfr'] = session('employee_id');
        if($xtrxm){
            $where['xtpfrxm'] = ['like',"%{$xtrxm}%"];
        }
        if($xtrgw){
            $where['gw'] = ['like',"%{$xtrgw}%"];
        }
        if($bflx){
            $where['bflx'] = ['like',"%{$bflx}%"];
        }
        if($fq){
            $where['fq'] = ['like',"%{$fq}%"];
        }
        if($sf){
            $where['sf'] = ['like',"%{$sf}%"];
        }
        if($cs){
            $where['cs'] = ['like',"%{$cs}%"];
        }
        if($cs){
            $where['jxsmc'] = ['like',"%{$jxsmc}%"];
        }
        if($wdmc){
            $where['wdmc'] = ['like',"%{$wdmc}%"];
        }
        if($start&&$end){
            $where['bfrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['bfrq'] = ['>',$start];
        }elseif($end){
            $where['bfrq'] = ['<',$end];
        }

        $count = db('yd_xtbf')->where($where)->count();
        $data = db('yd_xtbf')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /**
     * 我的协同拜访
     */
    public function mysynergybf(){

        $start = $this->request->param('start');
        $end = $this->request->param('end');
        $xtrxm = $this->request->param('xtrxm');
        $xtrgw = $this->request->param('xtrgw');
        $bflx = $this->request->param('bflx');
        $fq = $this->request->param('fq');
        $sf = $this->request->param('sf');
        $cs = $this->request->param('cs');
        $jxsmc = $this->request->param('jxsmc');
        $wdmc = $this->request->param('wdmc');
        $this->assign([
            'xtrxm'=>$xtrxm,
            'xtrgw'=>$xtrgw,
            'bflx'=>$bflx,
            'fq'=>$fq,
            'sf'=>$sf,
            'cs'=>$cs,
            'jxsmc'=>$jxsmc,
            'wdmc'=>$wdmc,
            'start'=>$start,
            'end'=>$end,
        ]);
        $where = [];
        $where['bfr'] = session('employee_id');
        if($xtrxm){
            $where['xtpfrxm'] = ['like',"%{$xtrxm}%"];
        }
        if($xtrgw){
            $where['gw'] = ['like',"%{$xtrgw}%"];
        }
        if($bflx){
            $where['bflx'] = ['like',"%{$bflx}%"];
        }
        if($fq){
            $where['fq'] = ['like',"%{$fq}%"];
        }
        if($sf){
            $where['sf'] = ['like',"%{$sf}%"];
        }
        if($cs){
            $where['cs'] = ['like',"%{$cs}%"];
        }
        if($cs){
            $where['jxsmc'] = ['like',"%{$jxsmc}%"];
        }
        if($wdmc){
            $where['wdmc'] = ['like',"%{$wdmc}%"];
        }
        if($start&&$end){
            $where['bfrq'] = ['between',[$start,$end]];
        }elseif($start){
            $where['bfrq'] = ['>',$start];
        }elseif($end){
            $where['bfrq'] = ['<',$end];
        }

        $count = db('yd_xtbf')->where($where)->count();
        $data = db('yd_xtbf')->where($where)->paginate(10,$count);
        $page = $data->render();
        $data = $data->items();
        foreach($data as $k=>$v){
            $data[$k] = $v;
        }
        $this->assign('data',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }


}